<?php

/**
 * User profile current password validator
 *
 */
class Application_Form_ProfilePasswordValidator extends Zend_Validate_Abstract
{
    protected $_user;
    
    protected $_messageTemplates = array(
        'passwordNotMatch' => "Current password did not match",
    );
    
    public function __construct(&$user)
    {
        $this->_user=$user;
    }
    
    /**
     * Validate interface isValid function
     *
     * @param string $value
     * @return bool
     */
    public function isValid($value)
    {
        if (empty($value)) return false;
        
        $this->_setValue($value);

        if ($this->_user->password != Application_Model_User::crypt_password($value))
        {
            $this->_error('passwordNotMatch');
            return false;
        }
        
        return true;
    }
}